package com.cn.zengzeng.spbzengzeng.service.impl;

import com.cn.zengzeng.spbzengzeng.mapper.UserAccountMapper;
import com.cn.zengzeng.spbzengzeng.po.UserPo;
import com.cn.zengzeng.spbzengzeng.service.UserAccountService;
import com.cn.zengzeng.spbzengzeng.utils.AESUtils;
import com.cn.zengzeng.spbzengzeng.utils.DateHelper;
import com.cn.zengzeng.spbzengzeng.vo.ActionResult;
import com.github.benmanes.caffeine.cache.Cache;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * @Author: ZhangZengZeng
 * @Date: 2023/3/31 14:27
 */
@Service
@Slf4j
public class UserAccountServiceImpl implements UserAccountService {

    @Resource
    private UserAccountMapper userAccountMapper ;
    @Override
    public int register (UserPo userPo) {
        Date date = new Date();
        userPo.setLevel("5");
        userPo.setStatus(0);
        userPo.setCreatetime(date);
        userPo.setLastsync(date);
        String encrypt = AESUtils.encrypt(userPo.getPassword());
        userPo.setPassword(encrypt);
        return userAccountMapper.register(userPo);
    }

    @Override
    public UserPo selectAccount (String account) {
        return userAccountMapper.selectAccount(account);
    }

    @Override
    public boolean activeAccount (String account) {
        int i = userAccountMapper.activeAccount(account);
        return i!=0;
    }

    @Override
    public boolean upPassWord (String account,String newPassWord) {
        int i = userAccountMapper.upPassWord(account,newPassWord);
        return i!=0;
    }

    @Override
    public boolean checkEmailUse (String email) {
        int i = userAccountMapper.checkEmailUse(email);
        return i>0;
    }

    @Override
    public boolean upPassWordByEmail (String email,String password) {
        int i = userAccountMapper.upPassWordByEmail(email,password);
        return i!=0;
    }
}
